<?php

namespace IMooc\Database;

/**
 * 'mysql_connect' 已在 PHP 7.0 版本中被移除
 */
class MySQL implements IDatabase
{
    protected $conn;

    function connect($host, $user, $passwd, $dbname): void
    {
        $conn = mysql_connect($host, $user, $passwd);
        mysql_select_db($dbname, $conn);
        $this->conn = $conn;
    }

    function query($sql)
    {
        return mysql_query($sql, $this->conn);
    }

    public function close(): void
    {
        mysql_close($this->conn);
    }
}